% lineStart=[0,0,0]'
% lineEnd=[5,3,0]';
% origin=[3,3,0]';

clear all;
dpi=1250;
sigma = 1e4                                                                                                                                                                                                  ;
threshold = 1e2;
miu=0.01;
sample1 = imread('D:\Desktop\test2.png');
sample2 = imread('D:\Desktop\test2.png');
[h,w,c] = size(sample2)
rate = [1/w,1/h]';
rate_reverse = [w,h]';
data= load('D:\Desktop\clusters\type1.txt');
data =cat(1,data',ones(1,size(data,1)));
offset=[125,130];
data_vec=  load('D:\Desktop\clusters\vec.txt')*dpi+offset;
data_vec =cat(1,data_vec',ones(1,size(data_vec,1)));
len=size(data_vec,2);
Angles={};
if(len<3)
    disp("len<3");
else
    for i=2:len-1
        origin = data_vec(:,i);
        lineStart = data_vec(:,i-1);
        lineEnd = data_vec(:,i+1);
        [ptPedal,pedalVec,angle] = CalVerticalVec(origin,lineStart,lineEnd);
        Angles{i-1}=angle;
    end
end

Angles = cell2mat(Angles);
figure(1)
clf
plot([lineStart(1),origin(1),lineEnd(1)],[lineStart(2),origin(2),lineEnd(2)],'o','LineWidth',2,'Color','red','Marker','.','MarkerSize',30,'MarkerEdgeColor','green');
hold on 
plot(ptPedal(1),ptPedal(2),'o','LineWidth',2,'Color','red','Marker','.','MarkerSize',30,'MarkerEdgeColor','red');
